<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>非父子组件间的传值</title>
    <script src="vue.js"></script>
</head>
<body>
<div id="app">
    <child content="Dell"></child>
    <child content="lee"></child>
</div>
<script>
    Vue.prototype.bus = new Vue();//

    var child = {
        props:['content'],
        data:function(){
            return {
                ctn:this.content
            }
        },
        template:"<div @click='handleClick'>{{ ctn }}</div>",
        methods:{
            handleClick:function () {
                this.bus.$emit('change',this.ctn)
            }
        },
        mounted:function () {
            var _this = this
            this.bus.$on('change',function (val) {//this的作用域发生变化
                console.log(val);
                _this.ctn = val
            })
        }
    };
    var vm = new Vue({
        el:"#app",
        components:{
            child:child
        },
        data:{},
        methods:{}
    });
</script>
</body>
</html>